﻿using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using LuxuryResort.Entity;

namespace LuxuryResort.Service.Mapping
{
    // Use a data contract as illustrated in the sample below to add composite types to service operations
    [DataContract]
    public class Room
    {
        [DataMember]
        public Guid RMID { get; set; }

        [DataMember]
        public string RoomNo { get; set; }

        [DataMember]
        public string RoomType { get; set; }

        [DataMember]
        public bool IsAvailable { get; set; }

        [DataMember]
        public decimal PriceUnit { get; set; }


        public static Room MapToRoom(Entity.Room efRoom)
        {
            if (efRoom == null) return null;

            var room = new Room
            {
                RMID = efRoom.RMID,
                RoomNo = efRoom.RoomNo.Value.ToString(),
                RoomType = efRoom.RoomType,
                IsAvailable = efRoom.IsAvailable != null && efRoom.IsAvailable.Value,
                PriceUnit = efRoom.PriceUnit == null ? 0m : efRoom.PriceUnit.Value
            };

            return room;
        }

        public static Entity.Room MapToEFRoom(Room serviceRoom)
        {
            if (serviceRoom == null) return null;

            var room = new Entity.Room
            {
                RMID = serviceRoom.RMID,
                RoomNo = Convert.ToInt32(serviceRoom.RoomNo),
                RoomType = serviceRoom.RoomType,
                IsAvailable = serviceRoom.IsAvailable,
                PriceUnit = serviceRoom.PriceUnit
            };

            return room;
        }
    }

    [DataContract]
    public class Reservation
    {
        [DataMember]
        public Guid RSID { get; set; }

        [DataMember]
        public Guid RMID { get; set; }

        [DataMember]
        public string CustomerName { get; set; }

        [DataMember]
        public int Quantity { get; set; }

        [DataMember]
        public string PaymentMethod { get; set; }

        [DataMember]
        public Guid CreatedBy { get; set; }

        [DataMember]
        public DateTime CreatedAt { get; set; }

        [DataMember]
        public DateTime CheckIn { get; set; }

        [DataMember]
        public DateTime CheckOut { get; set; }

        [DataMember]
        public Boolean? PaymentDone { get; set; }

        [DataMember]
        public int RoomNo { get; set; }

        [DataMember]
        public string Status { get; set; }

        [DataMember]
        public decimal? Total { get; set; }

        [DataMember]
        public string RoomType { get; set; }

        [DataMember]
        public decimal? RoomPrice { get; set; }

        public static Reservation MapToWcfReservation(Entity.Reservation reservation)
        {
            if (reservation == null) return null;

            var r = new Reservation
            {
                RSID = reservation.RSID,
                RMID = reservation.RMID,
                Quantity = reservation.Quantity,
                PaymentMethod = reservation.PaymentMethod,
                CustomerName = reservation.CustomerName,
                CreatedBy = reservation.CreatedBy,
                CreatedAt = reservation.CreatedAt,
                //RSID = Guid.NewGuid(),
                CheckIn = (DateTime) reservation.CheckIn,
                CheckOut = (DateTime) reservation.CheckOut,
                PaymentDone = reservation.PaymentDone,
                RoomNo = reservation.Room != null ? reservation.Room.RoomNo.Value : -1,
                Status = reservation.Status,
                Total = reservation.Total
            };

            return r;
        }

        public static Reservation MapToWcfReservation(KeyValuePair<string, Entity.Reservation> reservation)
        {
            //if (reservation is null) return null;

            var r = new Reservation
            {
                RSID = reservation.Value.RSID,
                RMID = reservation.Value.RMID,
                Quantity = reservation.Value.Quantity,
                PaymentMethod = reservation.Value.PaymentMethod,
                CustomerName = reservation.Value.CustomerName,
                CreatedBy = reservation.Value.CreatedBy,
                CreatedAt = reservation.Value.CreatedAt,
                //RSID = Guid.NewGuid(),
                CheckIn = (DateTime) reservation.Value.CheckIn,
                CheckOut = (DateTime) reservation.Value.CheckOut,
                RoomNo = reservation.Value.Room != null ? reservation.Value.Room.RoomNo.Value : -1,
                RoomType = reservation.Value.Room.RoomType,
                RoomPrice = reservation.Value.Room.PriceUnit,
                PaymentDone = reservation.Value.PaymentDone,
                Status = reservation.Value.Status,
                Total = reservation.Value.Total
            };

            return r;
        }

        public static Entity.Reservation MapToReservation(Reservation reservation)
        {
            if (reservation == null) return null;

            var r = new Entity.Reservation
            {
                RMID = reservation.RMID,
                Quantity = reservation.Quantity,
                PaymentMethod = reservation.PaymentMethod,
                CustomerName = reservation.CustomerName,
                CreatedBy = reservation.CreatedBy,
                CreatedAt = reservation.CreatedAt,
                RSID = reservation.RSID,
                CheckIn = reservation.CheckIn,
                CheckOut = reservation.CheckOut,
                PaymentDone = reservation.PaymentDone,
                Status = reservation.Status,
                Total = reservation.Total
            };

            return r;
        }
    }

    [DataContract]
    public class FoodOrder
    {
        [DataMember]
        public Guid ID { get; set; }

        [DataMember]
        public Guid FID { get; set; }

        [DataMember]
        public string CustomerName { get; set; }

        [DataMember]
        public Guid CreatedBy { get; set; }

        [DataMember]
        public DateTime CreatedAt { get; set; }

        [DataMember]
        public Boolean PaymentDone { get; set; }

        [DataMember]
        public int Quantity { get; set; }

        [DataMember]
        public decimal Total { get; set; }

        public static Food_Beverage_Order MapToFoodOrder(FoodOrder fo)
        {
            if (fo == null) return null;

            var item = new Food_Beverage_Order
            {
                ID = fo.ID,
                FID = fo.FID,
                CustomerName = fo.CustomerName,
                OrderedBy = fo.CreatedBy,
                OrderedAt = fo.CreatedAt,
                PaymentDone = fo.PaymentDone,
                Quantity = fo.Quantity,
                Total = fo.Total
            };

            return item;
        }
    }

    [DataContract]
    public class FoodBeverage
    {
        [DataMember]
        public Guid FID { get; set; }

        [DataMember]
        public string Name { get; set; }

        [DataMember]
        public string Type { get; set; }

        [DataMember]
        public decimal PriceUnit { get; set; }

        public static FoodBeverage MapToServiceFoodBeverage(Food_Beverage fb)
        {
            if (fb == null) return null;

            var food = new FoodBeverage
            {
                FID = fb.FID,
                Name = fb.Name,
                PriceUnit = fb.PriceUnit == null ? 0m : fb.PriceUnit.Value,
                Type = fb.Type
            };
            return food;
        }

        public static Food_Beverage MapToServiceFoodBeverage(FoodBeverage fb)
        {
            if (fb == null) return null;

            var food = new Food_Beverage
            {
                FID = fb.FID,
                Name = fb.Name,
                PriceUnit = fb.PriceUnit,
                Type = fb.Type
            };
            return food;
        }
    }

    [DataContract]
    public class LRMPReport
    {
        [DataMember]
        //Room/Food/Beverage
        public string Category { get; set; }

        [DataMember]
        public int RoomNo { get; set; }

        [DataMember]
        public string CustomerName { get; set; }

        [DataMember]
        public DateTime CheckIn { get; set; }

        [DataMember]
        public DateTime CheckOut { get; set; }

        [DataMember]
        public int Quantity { get; set; }

        [DataMember]
        public string FBName { get; set; }

        [DataMember]
        public string FBType { get; set; }

        [DataMember]
        public decimal PaymentAmount { get; set; }
    }

    [DataContract]
    public class LRMPNationalReport
    {
        [DataMember]
        public string ResortName { get; set; }

        [DataMember]
        public LRMPReport LocalReport { get; set; }
    }

    [DataContract]
    public class LRMPOccupancyReport
    {
        [DataMember]
        public int? RoomNo { get; set; }

        [DataMember]
        public decimal? RoomPrice { get; set; }

        [DataMember]
        public int TotalDays { get; set; }
    }
}